package com.hjy.search.web;

import com.hjy.common.utils.R;
import com.hjy.search.service.MallSearchService;
import com.hjy.search.vo.SearchParams;
import com.hjy.search.vo.SearchResult;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private MallSearchService mallSearchService;

    @RequestMapping({"list.html"})
    public String listIndex(SearchParams searchParams, Model model) throws IOException {
        SearchResult searchResult = mallSearchService.search(searchParams);
        model.addAttribute("result", searchResult);
        return "index";
    }

    @RequestMapping({"search.html"})
    public String searchIndex(SearchParams searchParams, Model model) throws IOException {
        SearchResult searchResult = mallSearchService.search(searchParams);
        model.addAttribute("result", searchResult);
        return "index";
    }

    @RequestMapping("/test")
    @ResponseBody
    public R test(User user,String hello, @RequestParam ArrayList<Integer> list) throws IOException {
        System.out.println("user = " + user);
        System.out.println("list = " + list);
        System.out.println("hello = " + hello);
        return R.ok().put("data",user);
    }

    @Data
    public static class User {
        private String username;
        private String password;
    }
}
